package homework.Demo1;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Account {
    private String id;
    private double money;
    private String name;
    private final Lock lock=new ReentrantLock();
    public Account()
    {
    }
    public Account(String id, double money) {
        this.id = id;
        this.money = money;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    public void dispositMoney(double money) {
        String tn=Thread.currentThread().getName();
        try {
            lock.lock();
            this.money += money;
            System.out.println(tn + " 存入"+money+"元后，账户余额是：" + this.money);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }

    }
}
